package com.base.system.jpa.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
import lombok.experimental.Accessors;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;

@Entity
@Table(name = "menu")
@org.hibernate.annotations.Table(appliesTo = "menu", comment = "菜单表")
@Data
@Accessors(chain = true)
@JsonIgnoreProperties(value = {"parent"}, ignoreUnknown = true)
public class JpaMenu {
    @Id
    @Column(name = "id", columnDefinition = "bigint COMMENT '主键，自动生成'")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "parent_id")
    private JpaMenu parent;

    @OneToMany
    @JoinColumn(name = "parent_id")
    @OrderBy("sortCode desc")
    @JsonInclude(JsonInclude.Include.NON_EMPTY)//如果是空就忽略
    @JsonIgnore
    private List<JpaMenu> children = new ArrayList();

    @Column(columnDefinition = "varchar(100) comment '文件路径，后缀是.vue'")
    private String filePath;

    @Column(columnDefinition = "varchar(50) NOT NULL comment 'url地址'", unique = true)
    private String url;
    @Column(columnDefinition = "varchar(50) NOT NULL comment '菜单中文名'", unique = true)
    private String nameZh;
    @Column(columnDefinition = "varchar(50) comment '排序code'")
    private Integer sortCode;
    @Column(columnDefinition = "varchar(150) comment '图标'")
    private String icon;
    @Column(columnDefinition = "bit(1) NOT NULL default 0 comment '是否不可用'")
    private Boolean isDisable;
}
